//
//  BSTextFiledView.m
//  MusicSample
//
//  Created by 李立达 on 2016/11/15.
//  Copyright © 2016年 JackWong. All rights reserved.
//

#import "BSTextFiledView.h"
#import "NSString+Common.h"

@interface BSTextFiledView ()
@property (nonatomic,strong)UITextField     *textfield;
@end

@implementation BSTextFiledView

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self initUI];
    }
    return self;
}

-(void)initUI
{
    self.layer.cornerRadius = 8;
    self.layer.borderWidth = 1;
    self.layer.borderColor = UIColorFromRGBA(0xd6d6d6,1).CGColor;
    self.textfield = [[UITextField alloc]init];
    self.textfield.bounds = CGRectMake(0, 0, self.width -40 , 18);
    self.textfield.center = CGPointMake(self.width/2, self.height/2);
    [self addSubview:self.textfield];
}

-(void)setTextColor:(UIColor *)textColor
{
    _textColor = textColor;
    self.textfield.textColor = _textColor;
}

-(void)setTextFont:(UIFont *)textFont
{
    _textFont = textFont;
    self.textfield.font = _textFont;
    [self.textfield sizeToFit];
    self.textfield.bounds = CGRectMake(0, 0, self.width -40 ,self.textfield.height);
    self.textfield.center = CGPointMake(self.width/2, self.height/2);
}
-(void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    self.textfield.placeholder = _placeholder;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
}
-(NSString *)text
{
    return [self msTrimmingCharacters:self.textfield.text];
}
-(NSString *)msTrimmingCharacters:(NSString *)aString{
    NSString *dn = [aString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    return [dn stringByReplacingOccurrencesOfString:@" " withString:@""];
}
@end


